<?php

/*
<!-- HTML FOR TESTING THE POST COMMAND -->
<html>
	<form action="adduser.php" method="post">
	Name: <input type="text" name="name" />
	Pass: <input type="text" name="pass" />
	<input type="submit" />
	</form>
</html>
*/

?>
<?php
	if ($_SERVER['REQUEST_METHOD'] == 'POST') {
	
		mysql_connect("localhost","akosciak","MojaPtaszek");
		
		mysql_select_db("songbump") or die( "Unable to select database");
		
		$values = "('".$_POST["name"]."',0,NULL)";
		$query = "INSERT INTO `Users`(`Name`, `CurrentlyPlaying`, `JoinedGroup`) VALUES ".$values;
		$result = mysql_query($query);
		
		// Check result
		// This shows the actual query sent to MySQL, and the error. Useful for debugging.
		if (!$result) {
			$returnVal = array("id" => -1);
			$returnJSON = json_encode($returnVal);
			echo $returnJSON;
			die();
		} else {
			$returnVal = array("id" => mysql_insert_id());
			$returnJSON = json_encode($returnVal);
			echo $returnJSON;
		}
	}
	
?>
